package org.apache.ibatis.io;

import com.sun.xml.internal.ws.model.ExternalMetadataReader;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;

import java.io.*;
import java.util.Properties;

/**
 * @author Clinton Begin
 * @worshiper MNIQXH
 */
@Deprecated
public class ExternalResources {

    private static final Log log = LogFactory.getLog(ExternalMetadataReader.class);

    private ExternalResources() {
        // Do Nothing
    }

    public static void copyExternalResource(File sourceFile, File destFile) throws IOException {
        if (!destFile.exists()) {
            destFile.createNewFile();
        }

        try (FileInputStream source = new FileInputStream(sourceFile);
             FileOutputStream destination = new FileOutputStream(destFile)) {
            destination.getChannel().transferFrom(source.getChannel(), 0, source.getChannel().size());
        }
    }

    public static String getConfiguredTemplate(String templatePath, String templateProperty) throws FileNotFoundException {
        String tempalteName = "";
        Properties migrationProperties = new Properties();

        try (InputStream is = new FileInputStream(templatePath)) {
            migrationProperties.load(is);
            tempalteName = migrationProperties.getProperty(templateProperty);
        } catch (FileNotFoundException e) {
            throw e;
        } catch (Exception e) {
            log.error("", e);
        }

        return tempalteName;
    }
}
